Skip to content

fix(novelty): estimate-only splits dollars by role and names the least sure one - #1218

Merged
antonwolfy merged 2 commits into
intel:mainfrom
antonwolfy:fix/novelty-estimate-role-usd
Nov 25, 2026
Merged

antonwolfy merged 2 commits into
intel:mainfrom
antonwolfy:fix/novelty-estimate-role-usd

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On main, novelty analyze --estimate-only (and --dry-run) prints one expected_usd and nothing says which role's token profile it leans on. The issue's run billed $6.00 for 777 calls where the estimate said expected_usd: 5.93 for 815 calls, with the extractor suspected (4 extractor calls of a triage run billed 16.4k output tokens, $0.38 of $0.95). That run was not repeated here; it rests on the issue's billed figures. On main the payload has no per-role dollars: the new tests fail on a missing usd_by_role key.

The issue offers two fixes. This PR takes the second, reporting which role the estimate is least sure of next to expected_usd. Refitting the token profile per role against measured runs per tier needs new paid runs per tier and role, which an offline build cannot make; it is left to #1217.

Closes #631

Changes

  • dokimi/novelty/tiers.py: usd_by_role is the one per-role pricing loop; estimate_usd keeps its signature and sums it, so expected_usd is unchanged.
  • dokimi/novelty/cost.py: role_usd prices each role's calls (panel judges after the first count under judge), least_sure_role applies the rule below, add_role_usd puts usd_by_role and least_sure_role in the estimate payload (both null when expected_usd is null), and least_sure_line formats the stderr line.
  • dokimi/commands/novelty_budget.py: run_estimate adds the two keys next to expected_usd; print_estimate_only prints Least sure of: <role> (<n>% of expected_usd): <reason> after the JSON and before the existing "Estimate only, nothing was measured" note. The Expected ~$X for this run at list prices line is untouched.
  • The rule: a run whose tier has no extractor profile of its own (study, or no tier) names extractor, since it borrows the standard profile; triage and standard name the role with the largest share of expected_usd, the first of extractor, answerer, judge on a tie.
  • Docs: docs/skill-novelty.md and docs/skill-novelty-walkthrough.md name the two fields and the rule.
  • Tests: new tests/test_novelty_estimate_roles.py; tests/test_novelty_settings_parity.py adds usd_by_role and least_sure_role to its bill keys (novelty analyze --estimate-only prices below the measured bill #631) and strips the new stderr line from the run, asserting it is there exactly when least_sure_role is not null. The golden file is not recaptured.
  • Changelog fragment (Added).
  • role_usd runs only after estimate_usd has resolved the role models and priced every role and panel judge, so its ValueError guard around role_models and its None return for an unpriced panel judge were unreachable and are removed; its None return for an unpriced role is covered by test_role_usd_is_none_for_an_unpriced_role.

Risk

The payload gains two keys and stderr gains one line; every existing value, call count and note keeps its wording, and expected_usd is computed by the same loop in the same order. A consumer that rejects unknown keys in the estimate JSON would notice. usd_by_role values are each rounded to 6 places, so they sum to expected_usd within rounding, not exactly.

Open PRs on the same files: #1190 changes the InputError import in run_estimate a few lines above this PR's hunk, and #1197 and #1176 edit other paragraphs of the two novelty docs; none touches the lines changed here. #1197 moves the novelty flags to PROVIDER/MODEL spellings: whichever merges second may need the new test's --model foo-bar-9 --provider openai written in the other form.

Testing

On a Linux review host, at b4c4e37d (on main 602de140):

  • make ci-local: 38 passed, 0 failed, 15 skipped (docker external-catalog smoke, the pinned Claude Code install, the jobs that do not run on a PR, the CLI-surface package step, conda-forge, other-Python matrix legs, fuzz, semgrep). 28393 tests passed, 23 skipped. A first run hit the 60 s timeout in tests/test_repo_typecheck_grader.py (untouched); alone it passed (108 passed), and the rerun was green.
  • The 10 new tests in tests/test_novelty_estimate_roles.py on main's code: 10 failed, each on a missing usd_by_role or least_sure_role key; here they pass.
  • Mutants, each failing the new tests: the extractor-profile check flipped, max to min, panel judges dropped, the percent inverted, the answerer's dollars doubled, an unpriced run giving zeros instead of null, the stderr line moved after the estimate note, a role dropped from the dict.
  • test_role_usd_is_none_for_an_unpriced_role (11th test in the file): with role_usd returning an empty split instead of None for an unpriced role, it fails. The coverage report on novelty/cost.py no longer lists lines 131-142.
  • On fastcontext with --tier triage --dry-run: usd_by_role is {"extractor": 0.076752, "answerer": 0.1846, "judge": 0.0915} for expected_usd: 0.352852, and stderr says Least sure of: answerer (52% of expected_usd).
  • Not run: the other Python versions (3.11, 3.12, 3.14), docker, and any paid run, so the issue's own run is not reproduced.

Open questions

Revert

A plain revert restores the payload and stderr of main. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to [no new raise or exit; the new tests name novelty analyze --estimate-only prices below the measured bill #631 in their module docstring]
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…ure (intel#631)

`novelty analyze --estimate-only` printed one `expected_usd` with no hint of which role's token profile it leans on, and a run billed above it (the issue's 777 calls at $6.00 against `expected_usd: 5.93`) gave no pointer to the extractor.

The payload now carries `usd_by_role` (extractor, answerer and judge list-price dollars, panel judges after the first under `judge`) and `least_sure_role` (a role and a reason), both null when `expected_usd` is null. A tier with no extractor profile of its own (`study`, or no tier) names the extractor, which borrows the standard profile; `triage` and `standard` name the role with the largest dollars. There is no per-role error data behind that rule. stderr prints one line with the role and its share before the existing estimate notes.

`tiers.estimate_usd` and the split share one pricing loop (`tiers.usd_by_role`); `expected_usd` and every existing note are unchanged. Refitting the token profile per tier needs measured paid runs and is left to a follow-up.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@exai-bot

exai-bot commented Nov 25, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 8 selected item(s).

CI at b4c4e37: 21 passing, 4 skipped.

Review details
  • Commit reviewed: b4c4e37 against merge base 602de14
  • Coverage: 8 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 102k tokens (48k from cache), 27s
  • Tool calls: 10 (6 file_read, 1 ci_status, 1 code_search, 1 linked_items, 1 local_check_results)
  • Role-based novelty USD cost estimates, budget integration, documentation, and tests: 8 files

@codecov-commenter

codecov-commenter commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.06%. Comparing base (602de14) to head (b4c4e37).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1218      +/-   ##
==========================================
- Coverage   96.07%   96.06%   -0.02%     
==========================================
  Files         496      496              
  Lines       65209    65314     +105     
  Branches    11317    11336      +19     
==========================================
+ Hits        62652    62746      +94     
- Misses       1583     1589       +6     
- Partials      974      979       +5     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/novelty_budget.py 97.03% <100.00%> (+0.13%) ⬆️
dokimi/dokimi/novelty/cost.py 96.49% <100.00%> (+1.19%) ⬆️
dokimi/dokimi/novelty/tiers.py 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…e guards

Settles the codecov concern on cost.py. role_usd runs only after estimate_usd has resolved the role models and priced every role and panel judge, so its ValueError guard around role_models and its None return for a panel judge's price could not be reached; they are gone. The remaining None return for an unpriced role is now covered by a test that calls role_usd with an unpriced model.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change class: CONTRACT (head b4c4e37)

  • Contract: changed (count signal only, no file:line)
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The per-role estimates include the extra panel judges and preserve an unknown total when pricing is unavailable. The documentation explains how the least-sure role is selected. The two focused novelty estimate suites passed locally (52 tests), and GitHub CI is green.

@antonwolfy
antonwolfy merged commit b40c0f8 into intel:main Nov 25, 2026
25 checks passed
@antonwolfy
antonwolfy deleted the fix/novelty-estimate-role-usd branch November 25, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

novelty analyze --estimate-only prices below the measured bill

4 participants